package Web.controller;

import Web.annotation.mySystemlog;
import Web.domain.ResponseResult;
import Web.domain.entity.Like;
import Web.domain.entity.User;
import Web.service.LikeService;
import Web.service.UserService;
import Web.utils.BeanCopyUtils;
import Web.vo.UserDetailVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    //UserService是我们在huanf-framework工程写的接口
    private UserService userService;

    @Autowired
    private LikeService likeService;
    @GetMapping("/userInfo")
    @mySystemlog(xxbusinessName = "查询个人信息")
    public ResponseResult userInfo(){
        //查询个人信息
        return userService.userInfo();
    }

    @PutMapping("userInfo")
    @mySystemlog(xxbusinessName = "更新用户信息")
    public ResponseResult  updateUserInfo(@RequestBody User user){
        //更新个人信息
        return userService.updateUserInfo(user);
    }

    @PostMapping("/register")
    @mySystemlog(xxbusinessName = "用户注册")
    public ResponseResult register(@RequestBody User user){
        //注册功能
        return userService.register(user);
    }
    @ApiOperation("更新用户粉丝和关注数量")
    @PutMapping("/updateUserLike")
    public ResponseResult setLike(@RequestBody Like like){
        Integer result= likeService.setLike(like);
        if(result==1){
            long change=1;
            userService.updateLikedCount(like.getUserLikeId(), change);
            return userService.updateLikeCount(like.getUserId(),change);
        }
        else{
            long change=-1;
            userService.updateLikedCount(like.getUserLikeId(), change);
            return userService.updateLikeCount(like.getUserId(),change);
        }
    }

    @GetMapping("/{id}") //路径参数形式的HTTP请求，注意下面那行只有加@PathVariable注解才能接收路径参数形式的HTTP请求
    //ResponseResult是huanf-framework工程的domain目录的类
    public ResponseResult getArticleDetail(@PathVariable("id") Long id) {//注解里指定的id跟上一行保持一致

        return userService.getUserDetail(id);

    }
}